/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.adama.entite;

import fr.adama.entite.modele.ModelePaie;
import fr.adama.entite.typePerso.EtatContrat;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.OrderBy;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.springframework.format.annotation.DateTimeFormat;

/**
 *
 * @author mini-john
 */
@Entity
@Table(uniqueConstraints = @UniqueConstraint(name = "CONTRATADHERENTEMPLOYEEXISTE", columnNames = {"employe_id", "adherent_id", "dateEntree"}))
@Indexed
@Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
public class Contrat implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "contrat_sequence")
    @SequenceGenerator(name = "contrat_sequence", sequenceName = "contrat_sequence")
    private Long id;
    @ManyToOne
    @IndexedEmbedded
    private Employe employe;
    BigDecimal salaireBase;
    @ManyToOne
    @IndexedEmbedded
    private Adherent adherent;
    @Temporal(javax.persistence.TemporalType.DATE)
    @DateTimeFormat(pattern = "dd MM yyyy")
    private Date dateEntree;
    @Enumerated(EnumType.STRING)
    private EtatContrat etatContrat;
    @OneToOne()
    private ModelePaie modelPaie;

    @OneToMany(mappedBy = "contrat", fetch = FetchType.LAZY)
    @OrderBy(clause = "periode")
    private List<BulletinPaie> bulletinPaie;
    @OneToMany(mappedBy = "contrat", fetch = FetchType.LAZY)
    @OrderBy(clause = "periode")
    private List<Facture> factures;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Employe getEmploye() {
        return employe;
    }

    public void setEmploye(Employe employe) {
        this.employe = employe;
    }

    public Adherent getAdherent() {
        return adherent;
    }

    public void setAdherent(Adherent adherent) {
        this.adherent = adherent;
    }

    public Date getDateEntree() {
        return dateEntree;
    }

    public void setDateEntree(Date dateEntree) {
        this.dateEntree = dateEntree;
    }

    public List<BulletinPaie> getBulletinPaie() {
        return bulletinPaie;
    }

    public void setBulletinPaie(List<BulletinPaie> bulletinPaie) {
        this.bulletinPaie = bulletinPaie;
    }

    public BigDecimal getSalaireBase() {
        return salaireBase;
    }

    public void setSalaireBase(BigDecimal salaireBase) {
        this.salaireBase = salaireBase;
    }

    public EtatContrat getEtatContrat() {
        return etatContrat;
    }

    public void setEtatContrat(EtatContrat etatContrat) {
        this.etatContrat = etatContrat;
    }

    public ModelePaie getModelPaie() {
        return modelPaie;
    }

    public void setModelPaie(ModelePaie modelPaie) {
        this.modelPaie = modelPaie;
    }

    public List<Facture> getFactures() {
        return factures;
    }

    public void setFactures(List<Facture> factures) {
        this.factures = factures;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contrat)) {
            return false;
        }
        Contrat other = (Contrat) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.adama.entite.Contrat[ id=" + id + " ]";
    }

}
